package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-04-28
 * Time: 19:41
 */
public class TestDemo15 {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            while (!Thread.interrupted()){
                System.out.println("hello Thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("进行收尾工作");
                    break;
                }
            }
        });
        t.start();

        try {
            // main 线程休眠5秒
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 使用 interrupt 方法修改线程标志位，使线程中断
        t.interrupt();
    }
}
